from django.urls import path
from . import views
from .views import (
    news_view, WorkerListView, NoticeViewSet,
    CommentViewSet, WorkerDetailView, DingTalkRobotView
)

app_name = 'home'

# 通知相关视图
notice_list_view = views.NoticeViewSet.as_view({
    'get': 'list',          # 获取通知列表
    'post': 'create',       # 创建通知
})

notice_detail_view = views.NoticeViewSet.as_view({
    'get': 'retrieve',      # 获取通知详情
    'put': 'update',        # 更新通知
    'delete': 'destroy',    # 删除通知
})

# 评论相关视图
comment_list_view = views.CommentViewSet.as_view({
    'get': 'list',          # 获取评论列表
    'post': 'create',       # 创建评论
})

comment_detail_view = views.CommentViewSet.as_view({
    'get': 'retrieve',      # 获取评论详情
    'put': 'update',        # 更新评论
    'delete': 'destroy',    # 删除评论
})

urlpatterns = [
    # 新闻相关
    path('news/', news_view, name='news_view'),
    
    # 员工管理
    path('workers/', WorkerListView.as_view(), name='worker_list'),
    path('workers/<int:pk>/', WorkerDetailView.as_view(), name='worker_detail'),
    path('workers/export/', views.export_excel, name='export_excel'),
    path('workers/import/', views.import_excel, name='import_excel'),

    # 通知管理
    path('notices/', notice_list_view, name='notice_list'),
    path('notices/<int:pk>/', notice_detail_view, name='notice_detail'),
    path('notices/<int:pk>/like/', views.NoticeViewSet.as_view({'post': 'like'}), name='notice_like'),
    path('notices/<int:pk>/read/', views.NoticeViewSet.as_view({'put': 'read'}), name='notice_read'),
    path('notices/mark-all-read/', views.NoticeViewSet.as_view({'post': 'mark_all_read'}), name='notice_mark_all_read'),

    # 评论管理
    path('notices/<int:notice_id>/comments/', comment_list_view, name='comment_list'),
    path('notices/<int:notice_id>/comments/<int:pk>/', comment_detail_view, name='comment_detail'),
    path('notices/<int:notice_id>/comments/<int:pk>/like/', views.CommentViewSet.as_view({'post': 'like'}), name='comment_like'),

    # 钉钉集成
    path('dingtalk/robot/', DingTalkRobotView.as_view(), name='dingtalk-robot'),
    path('dingtalk/send/', views.send_dingtalk_message, name='send_dingtalk_message'),
]